package com.ml.mall.service.company.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ml.mall.bean.req.company.CompanyBankDto;
import com.ml.mall.consts.CommonConsts;
import com.ml.mall.entity.company.SysCompanyBank;
import com.ml.mall.mapper.company.SysCompanyBankMapper;
import com.ml.mall.service.company.SysCompanyBankService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysCompanyBankServiceImpl extends ServiceImpl<SysCompanyBankMapper, SysCompanyBank> implements SysCompanyBankService {

    @Autowired
    private SysCompanyBankMapper sysCompanyBankMapper;

    /**
     * 公司银行信息是否完整
     * @param companyBank
     * @return
     */
    @Override
    public boolean isCompletedBankDetail(SysCompanyBank companyBank, Integer companyType) {
        //买家不用检测银行信息
        if(CommonConsts.ROLE_TYPE_PURCHASE.equals(companyType)){
            return true;
        }

        if(null == companyBank){
            return false;
        }

        //忽略检验
//        if(null == companyBank.getBankAccountNumber()
//                || StrUtil.isBlank(companyBank.getBankCode())
//                || StrUtil.isBlank(companyBank.getBankName())
//                || StrUtil.isBlank(companyBank.getBankSwfit())){
//            return false;
//        }

        return true;
    }

    @Override
    public void saveCompanyBankService(CompanyBankDto bankDetails, Long companyId) {
        if(null != bankDetails){
            SysCompanyBank sysCompanyBank = new SysCompanyBank();
            BeanUtils.copyProperties(bankDetails,sysCompanyBank);
            sysCompanyBank.setCompanyId(companyId);
            sysCompanyBank.setState(CommonConsts.FIXED_NUM_ZERO);
            sysCompanyBankMapper.insert(sysCompanyBank);
        }
    }
}
